/**
 * 向后端请求用户的菜单，动态生成路由
 */
import { generatorDynamicRouter } from '@/router/generator-routers'
import {constantRoutes,asyncRoutes } from '@/router'
const asyncRouter = {
  namespaced: true,
  state: {
    routes: [],
    addRoutes: []
  },
  mutations: {
    SET_ROUTERS: (state, routers) => {
      state.addRoutes = routers
      state.routes = constantRoutes.concat(routers)
    }
  },
  actions: {
    GenerateRoutes ({ commit }, data) {
      return new Promise(resolve => {
        generatorDynamicRouter().then(routers => {
          commit('SET_ROUTERS', routers)
          resolve(routers)
        })
      })
    }
  }
}

export default asyncRouter
